//***************************程序逻辑控制**********************************
public class Test {
    public static void main1(String[] args) {
        int a = 10;
        if(a > 0) {
            System.out.println("a > 0");
        }
        else if(a == 0) {
            System.out.println("a == 0");
        }
        else {
            System.out.println("a < 0");
        }

        //判断一个数是奇数还是偶数
        int n = 10086;
        if(n % 2 == 0) {
            System.out.println(n + "是偶数");
        }
        else {
            System.out.println(n + "是奇数");
        }

        //判断闰年
        int year = 2025;
        if((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
            System.out.println(year + "是闰年");
        }
        else {
            System.out.println(year + "不是闰年");
        }
    }

    public static void main2(String[] args) {
        int day = 5;
        //注意 switch内的基本类型不能是long float double bool --- 其余都可以
        switch(day) {
            default:
                System.out.println("错误！！！");
                break;
            case 1:
                System.out.println("周一");
                break;
            case 2:
                System.out.println("周二");
                break;
            case 3:
                System.out.println("周三");
                break;
            case 4:
                System.out.println("周四");
                break;
            case 5:
                System.out.println("周五");
                break;
            case 6 :
                System.out.println("周六");
                break;
            case 7:
                System.out.println("周日");
                break;
        }
    }


    public static void main3(String[] args) {
        //打印1~10的数字
        int i = 1;
        while(i <= 10) {
            System.out.print(i + " ");
            ++i;
        }
        System.out.println();

        //计算1~100的和
        int j = 1;
        int sum = 0;
        while(j <= 100) {
            sum += j;
            ++j;
        }
        System.out.println("1 ~ 100 的和为：" + sum);

        //计算5的阶乘
        int k = 1;
        int ret = 1;
        while(k <= 5) {
            ret *= k;
            ++k;
        }
        System.out.println("5的阶乘为：" + ret);

        //计算1！ + 2！ + 3！ + 4！ + 5！
        int a = 1;
        int sum1 = 0;
        while(a <= 5) {
            int b = 1;
            int ret1 = 1;
            while(b <= a) {
                ret1 *= b;
                ++b;
            }
            ++a;
            sum1 += ret1;
        }
        System.out.println(sum1);

        //使用break找到100~200中第一个能被3整除的数
        int m = 100;
        while(1 <= 200) {
            if(m % 3 == 0) {
                System.out.println("第一个能被3整除的是：" + m);
                break;
            }
            m++;
        }

        //使用continue找到100~200中可以被3整除的所有数
        int z = 100;
        while(z <= 200) {
            if(z % 3 == 0) {
                System.out.print(z + " ");
                z++;
                continue;
            }
            z++;
        }
    }


    public static void main4(String[] args) {
        for (int i = 1; i <= 10; i++) {
            System.out.print(i + " ");
        }
        System.out.println();

        //求1~100的和
        int sum = 0;
        for (int i = 1; i <= 100; i++) {
            sum += i;
        }
        System.out.println(sum);

        //求5的阶乘
        int ret = 1;
        for (int i = 1; i <= 5; i++) {
            ret *= i;
        }
        System.out.println(ret);

        //求1！+ 2！+ 3！ + 4！ + 5！
        int sum1 = 0;
        for (int i = 1; i <= 5; i++) {
            int ret1 = 1;
            for (int j = 1; j <= i; j++) {
                ret1 *= j;
            }
            sum1 += ret1;
        }
        System.out.println(sum1);
    }


        //找到1~100中所有的素数 ---- 只能被1和本身整数
        public static void main5(String[] args) {
            for(int i = 1; i <= 100; i++) {
                boolean flag = true;
                for(int j = 2; j < i; j++) {
                    if(i % j == 0) {
                        flag = false;//如果不是素数，那么置为假
                        break;
                    }
                }
                if(flag) {
                    System.out.print(i + " ");
                }
            }
            System.out.println();
        }


        //1~6的自幂数
        public static void main6(String[] args) {
            for(int i = 1; i <= 999999; i++) {
                int tmp = i;
                int sum = 0;
                int cnt = 0;
                while(tmp != 0) {
                    cnt++;
                    tmp /= 10;
                }
                tmp = i;//重新赋值
                while(tmp != 0) {
                    sum += Math.pow(tmp % 10, cnt);//开次方
                    tmp /= 10;
                }
                if(sum == i) {
                    System.out.println(cnt + "位的自幂数有：" + sum);
                }
            }
        }

        //1000~2000之间所有的闰年
        public static void main7(String[] args) {
            for(int i = 1000; i <= 2000; i++) {
                if((i % 4 == 0 && i % 100 != 0) || (i % 400 == 0)) {
                    System.out.println(i + "是闰年");
                }
            }
        }


        //1到 100 的所有整数中出现多少个数字9
        public static void main8(String[] args) {
            int cnt = 0;
            for(int i = 1; i <= 100; i++) {
                int tmp = i;
                while(tmp != 0) {
                    if(tmp % 10 == 9) {
                        cnt++;
                    }
                    tmp /= 10;
                }
            }
            System.out.println(cnt);
        }



        //计算1/1-1/2+1/3-1/4+1/5 …… + 1/99 - 1/100 的值
    public static void main(String[] args) {
        double sum = 0;
        int flag = 1;
        for (int i = 1; i <= 100; i++) {
            sum += ((1.0 / i) * flag);
            flag = -flag;
        }
        System.out.println(sum);
    }



}

































